#version 330 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;

struct VS_OUT
{
    //世界空间坐标
    vec3 vertex;
    //世界空间法线
    vec3 normal;
    //纹理坐标
    vec2 texcoord;
};
in VS_OUT vs_out[];


struct GEO_OUT
{
    //世界空间坐标
    vec3 vertex;
    //模型控件法线
    vec3 normal;
    //纹理坐标
    vec2 texcoord;
};
out GEO_OUT geo_out;


vec3 GetNormalModel()
{
    vec3 a = vec3(vs_out[2].vertex) - vec3(vs_out[1].vertex);
    vec3 b = vec3(vs_out[0].vertex) - vec3(vs_out[1].vertex);
    return normalize(cross(a, b));
}

vec3 GetNormalDev()
{
    vec3 a = vec3(gl_in[0].gl_Position) - vec3(gl_in[1].gl_Position);
    vec3 b = vec3(gl_in[2].gl_Position) - vec3(gl_in[1].gl_Position);
    return normalize(cross(a, b));
}
void main()
{
    //geo_out.normal = GetNormalModel();
    geo_out.vertex = vs_out[0].vertex;
    geo_out.normal = vs_out[0].normal;
    geo_out.texcoord=vs_out[0].texcoord;
    gl_Position = gl_in[0].gl_Position;
    EmitVertex();

    geo_out.vertex = vs_out[1].vertex;
    geo_out.normal = vs_out[1].normal;
    geo_out.texcoord=vs_out[1].texcoord;
    gl_Position = gl_in[1].gl_Position;
    EmitVertex();

    geo_out.vertex = vs_out[2].vertex;
    geo_out.normal = vs_out[2].normal;
    geo_out.texcoord=vs_out[2].texcoord;
    gl_Position = gl_in[2].gl_Position;
    EmitVertex();
    EndPrimitive();
}
